// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './app'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import axios from 'axios'
import url from './common/url'
Vue.config.productionTip = false

Vue.use(ElementUI);

Vue.prototype.url = url;
Vue.prototype.axios = axios;
Vue.prototype.TOKEN = window.sessionStorage.getItem('token');
window.log = console.log.bind(console)

router.beforeEach((route, redirect, next) => {
    
    
        if (route.path === '/login') {
            window.sessionStorage.removeItem('token') 
        }
        let user = window.sessionStorage.getItem('token')
        if (!user && route.path !== '/login') {
            next({ path: '/login' })
        } else {
            if (route.name != '') {
                next()
            } else {
                next({ path: '/mySchedule' })
            }
        }
    })


/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    template: '<App/>',
    components: { App }
})
